package com.ruoyi.ggsearch.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.ggsearch.domain.GgDomain;
import com.ruoyi.ggsearch.domain.GgKeyWords;
import com.ruoyi.ggsearch.domain.GgSearchResult;
import com.ruoyi.ggsearch.service.IGgDomainService;
import com.ruoyi.ggsearch.service.IGgKeyWordsService;
import com.ruoyi.ggsearch.service.IGgSearchResultService;
import com.ruoyi.ggsearch.service.IGgSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

/**
 * 查询结果记录Controller
 *
 * @author yangjin
 * @date 2023-04-07
 */
@RestController
@RequestMapping("/ggSearch")
public class GgSearchController extends BaseController
{
    @Autowired
    private IGgDomainService ggDomainService;
    @Autowired
    private IGgKeyWordsService ggKeyWordsService;

    @Autowired
    private IGgSearchService ggSearchService;

    /**
     * 查询谷歌排名
     */
    @Log(title = "查询结果记录", businessType = BusinessType.UPDATE)
    @PostMapping("/goSearch")
    public AjaxResult goSearch()
    {
        List<GgKeyWords> listKeyWords = ggKeyWordsService.selectGgKeyWordsList(new GgKeyWords());
        List<GgDomain> listDomain = ggDomainService.selectGgDomainList(new GgDomain());
        try {
            ggSearchService.goSearchAndSave(listKeyWords, listDomain);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        System.out.println("================搜索排名结束，发送钉钉通知！====================");
        return null;
    }
}
